import $ from 'jquery'

export function fitWindowSize(scale, el = '.window') {
  const originHeight = document.documentElement.clientHeight || document.body.clientHeight;
  const originWidth = document.documentElement.clientWidth || document.body.clientWidth;
  if (typeof scale === 'undefined') {
    scale = originWidth >= 1366 ? 0.9 : 1;
  }
  const targetHeight = originHeight * scale;
  const targetWidth = originWidth * scale;
  el = document.querySelector(el);
  el.style.height = targetHeight + 'px'; 
  el.style.width = targetWidth + 'px';
  el.style.margin = `-${targetHeight / 2}px 0 0 -${targetWidth / 2}px`
}

export function showWindow(el, component) {
  const $win = $(el);
  $win.addClass('showWindow');
  if (component && typeof component.methods.openCallback === 'function') {
    component.methods.openCallback(component)
  }
}

export function hideWindow(el) {
  const $win = $(el);
  $win.removeClass('showWindow');
}